﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Protocol.stage;
using Pixysoft.Weblications.Sango.Formular;
using Pixysoft.Weblications.Sango.Environment;
using Pixysoft.Weblications.Sango.Dao;
using Pixysoft.Weblications.Sango.Protocol;

namespace Pixysoft.Weblications.Sango.Command.stage
{
    /// <summary>
    /// 获取关卡可攻打次数
    /// </summary>
    partial class SangoStageHandler
    {
        public stage_info stage_info(long stageserialcode)
        {
            string userCode = SangoManager.Authentication();

            stage_info response = ReflectionManager.CreatePojo<stage_info>();
            response.Succeed = false;

            Entities.War_Stage stage = WarStageHelper.searchStageByCode(stageserialcode);

            Entities.Usr_Profile profile = UsrProfileDao.getUsrProfile(userCode);

            Entities.Usr_Activity activity = UsrActivityDao.getHistory(userCode);

            Entities.Usr_Section section = UsrSectionDao.GetSection(userCode);

            long times = 0;

            if (stage.Stageplaytimes >= 0)
            {
                times = stage.Stageplaytimes - WarStagehistoryHelper.searchHistory(section.Sectionserialcode, stage.Stageserialcode).Attackcount;

                if (times > stage.Stageplaytimes)
                {
                    times = stage.Stageplaytimes;
                }
            }
            else
            {
                times = 0;
            }

            response.stage = StageFacade.toStage(stage, profile);
            response.description = stage.Description;
            response.times = times;
            response.Succeed = true;
            return response;
        }

    }
    public interface stage_info : ISangoResponse
    {
        stage_stage stage { get;set;}

        string description { get;set;}

        long times { get;set;}
    }
}
